//
//  ResultCell.m
//  iiecg
//
//  Created by Shanlin on 2017/3/24.
//  Copyright © 2017年 Boundary Technology. All rights reserved.
//

#import "ResultCell.h"

@interface ResultCell ()
//@property (weak, nonatomic) IBOutlet UIButton *messageButton;
@property(weak,nonatomic)UITableView *tableView;
@property (nonatomic,strong)ResultBean *bean;//
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UILabel *ecgResultLabel;
@property (weak, nonatomic) IBOutlet UILabel *lab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labHeightconstrain;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ecgResultConstraintsH;

@end

@implementation ResultCell


-(void)setBean:(ResultBean *)bean
{
    __weak typeof(self)weakSelf = self;
    _bean = bean;
    weakSelf.ecgResultLabel.text = bean.resultText;
    [IKPublicUtil runOnMainThread:^{
//        weakSelf.messageButton.text = weakSelf.bean.resultText;
        if (weakSelf.bean.resultType == ResultTypeNormal) {
            weakSelf.ecgResultLabel.textColor = ECG_COLOR_GREEN;
            weakSelf.lab.textColor = ECG_COLOR_GREEN;
            weakSelf.ecgResultLabel.hidden = YES;
            weakSelf.lab.text = [NSString stringWithFormat:@"%@%@", INTERNATIONAL(@"string_auto_analys"), INTERNATIONAL(@"string_nomal")];
            weakSelf.labHeightconstrain.constant = scale(78) - 20;
        }else{
            weakSelf.ecgResultLabel.textColor = ECG_COLOR_ORANGE;
            weakSelf.lab.text = [NSString stringWithFormat:@"%@%@", INTERNATIONAL(@"string_auto_analys"), INTERNATIONAL(@"string_not_nomal")];
            weakSelf.lab.textColor = ECG_COLOR_ORANGE;
            weakSelf.labHeightconstrain.constant = scale(49);
            weakSelf.ecgResultConstraintsH.constant = scale(39) - 15;
            weakSelf.ecgResultLabel.hidden = NO;
        }
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    _messageButton.adjustsImageWhenHighlighted = NO;
//    _messageButton.enabled = YES;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.ecgResultLabel.userInteractionEnabled = YES;
    self.ecgResultLabel.numberOfLines = 0 ;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(godown:)];
    [self.ecgResultLabel addGestureRecognizer:tap];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+(instancetype)createWith:(UITableView *)tableView bean:(ResultBean *)bean
{
    static NSString *ID = @"ResultCell";
    ResultCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:ID owner:nil options:nil] lastObject];
    } else {
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    cell.bean = bean;
    cell.tableView = tableView;
    return cell;

}

-(void)godown:(UITapGestureRecognizer *)tap
{
    __weak typeof(self)weakSelf = self;
    [weakSelf.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

}


@end
